package com.herench.bs.handler;


import com.herench.bs.agent.IOutpatientClinicAgent;
import com.herench.bs.annotation.Handler;
import com.herench.bs.support.AbstractMessageHandler;
import com.herench.bs.support.RequestMessage;
import com.herench.bs.support.ResponseMessage;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

import java.util.Map;


/**
 * Created by liuxiaohui on 2019/3/26.
 */
@Component
@Handler(code = "100750",name="提取创建患者数据：EstablishPatient()")
public class EstablishPatientHandler extends AbstractMessageHandler {

    @Override
    protected ResponseMessage innerHandler(RequestMessage requestMessage) throws Exception {
        ResponseMessage responseMessage = new ResponseMessage(requestMessage.getId());

        // **************** 微信前端传入的参数 ******************************************* Start
        // 系统编码：微信前端区分医院用
        String channelCode = requestMessage.getArgsPropertyStringValue("sysCode");
        // 身份证号
        String idNo = requestMessage.getArgsPropertyStringValue("idNo");
        Assert.notNull(idNo, "身份证号（idNo）： 不可为空！");

        // 姓名
        String name = requestMessage.getArgsPropertyStringValue("name");
        // 年龄
        String age = requestMessage.getArgsPropertyStringValue("age");
        // 生日
        String birthday = requestMessage.getArgsPropertyStringValue("birthday");
        // 性别，中文（男、女、未知）
        String sex = requestMessage.getArgsPropertyStringValue("sex");
        // 住址
        String address = requestMessage.getArgsPropertyStringValue("address");
        // 民族，中文（汉族，回族等）
        String nation = requestMessage.getArgsPropertyStringValue("nation");
        // 出生地，代码
        String birthPlace = requestMessage.getArgsPropertyStringValue("birthPlace");
        // 邮政编码
        String zipCode = requestMessage.getArgsPropertyStringValue("zipCode");
        // 手机号码
        String phoneNumberHome = requestMessage.getArgsPropertyStringValue("phoneNumberHome");
        // 身份，中文
        String identity = requestMessage.getArgsPropertyStringValue("identity");
        // 费别，中文
        String chargeType = requestMessage.getArgsPropertyStringValue("chargeType");
        // 婚姻状况，代码
        String maritalStatus = requestMessage.getArgsPropertyStringValue("maritalStatus");
        // 医保卡号
        String insurNo = requestMessage.getArgsPropertyStringValue("insurNo");
        // 医保卡密码
        String insurPwd = requestMessage.getArgsPropertyStringValue("insurPwd");
        // 卡号
        String cardNo = requestMessage.getArgsPropertyStringValue("cardNo");
        // 卡类型
        String cardType = requestMessage.getArgsPropertyStringValue("cardType");
        // 个人编码
        String personNo = requestMessage.getArgsPropertyStringValue("personNo");
        // 是否匿名
        String isAnonymous = requestMessage.getArgsPropertyStringValue("isAnonymous");
        // **************** 微信前端传入的参数 ******************************************* End

        // 医院代码：微信后端区分医院用
        String hospitalCode = getCleverClinicContext().getHospitalCodeByChannelCode(channelCode);

        // 获取Bean信息
        IOutpatientClinicAgent outpatientClinicAgent = getCleverClinicContext().getApplicationContext().getBean(IOutpatientClinicAgent.class);
        // 设定入参
        Map<String, Object> res = outpatientClinicAgent.establishPatient(channelCode, hospitalCode, idNo, name, age, birthday, sex, address, nation, birthPlace, zipCode, phoneNumberHome, identity, chargeType, maritalStatus, insurNo, insurPwd, cardNo, cardType, personNo, isAnonymous);

        // 设置应答信息
        responseMessage.setData(res);
        getPropertiesFromInvokerResultMap(responseMessage, res);

        return responseMessage;
    }
}
